package com.fhz.a2102high6.test2

/**
 * 时间:2023/9/12
 * @author Mr.Feng
 * 简述: TODO
 */
fun main(){
    val list = listOf("Apple", "Banana", "Orange", "Pear", "Grape")
    val builder = StringBuilder()
    builder.append("Start eating fruits.\n")
    for (fruit in list) {
        builder.append(fruit).append("\n")
    }
    builder.append("Ate all fruits.")
    val result = builder.toString()
    println(result)

    //with 返回最后一行
    val with = with(builder) {
        append("12")
        append(12)
        append(12)
    }
    with.append("12")

    //run 也返回最后一行
    val run = builder.run {
        append(1)
        append(2)
    }
    run.append(1)

    //返回当前对象
    val apply = builder.apply {
        append(1)
        append(1)
    }
    apply.append(1)




}